package com.fomky.queried.common.connect;

import lombok.Builder;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;


@Data
@Builder
public class RowDataList implements Serializable {
    private List<SchemaColumn> columns;
    private List<Map<String,Object>> row;

    public static RowDataList of(List<RowData> rowDataList) {
        List<Map<String,Object>> row = new ArrayList<>();
        List<SchemaColumn> columnList = null;
        for (RowData rowData : rowDataList) {
            if(Objects.isNull(columnList)) {
                columnList = rowData.columns;
            }
            row.add(rowData.getData());
        }
        return RowDataList.builder()
                .columns(columnList)
                .row(row).build();
    }
}
